package com.yunfei.springbootgoods.controller;

import com.yunfei.springbootgoods.dto.Result;
import com.yunfei.springbootgoods.entity.Category;
import com.yunfei.springbootgoods.exception.MyException;
import com.yunfei.springbootgoods.exceptionEnums.ExceptionEnum;
import com.yunfei.springbootgoods.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping(value = "/getCategoryList")
    public Result getCategoryList(){

        try {
            List<Category> categoryList = categoryService.getCategoryList();
            Result result = new Result();
            result.setData(categoryList);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(ExceptionEnum.ERROR_CATEGORY_LIST);
        }
    }
}
